(function($ , window){
	function uploadfile(){};
	uploadfile.prototype.upload = function(options , callabck){
		var $form = "",
			$iframe = "",
			$input = "",
			type = /\w\.(jpg|png|gif|bmp)$/,
			$body = $("body");
		//提示
		if(!options.fileBtn){
			error("点击按钮不存在");
			return false;
		};
		if(!options.url){
			error("图片上传地址不能为空");
			return false;
		};
		$iframe = $('<iframe style="display:none" class="file-iframe" src=""></iframe>');
		$body.append($iframe);
		//事件
		$(options.fileBtn).click(function(){
			//清空
			$iframe.contents().find("body").html("");
			//遍历 
			$form = $('<form class="form" action="'+options.url+'" method="'+(options.method || "post")+'" enctype="multipart/form-data">'+'<input type="file" name="upload" multiple="multiple">'+'</form>');
			$input = $form.find("input");
			$iframe.contents().find("body").append($form);
			//出发input的点击事件
			$input.trigger("click");
			$input.click(function(){
				console.log("this");
			});
			$input.on("change" , function(){
				//判断格式是否正确
				if(type.test($(this).val())){
					$form.submit();
					getData();
				}else{
					error("格式不正确");
					return false;
				};
			});
		});
		//上传成功
		function getData(){
			$iframe.on("load" , function(){
				var data = $iframe.contents().find("body").html();
				console.log(data);
				callabck && callabck(eval(data)[0]);
			});
		};
		//提示
		function error(msg){
			return alert(msg);
		};
	};
	window.uploadfile = new uploadfile();
})($ , window)
